from ConvexProject.convex_optimization.system_initialization import *
from ConvexProject.convex_optimization.userassociation_main import userassociation_energysharing_once
from ConvexProject.parameter import const


# 根据parameter中的参数用例
np.random.seed(const.SEED)
bs_num = const.BS_NUM
ue_num = const.UE_NUM_SEQUENCE[0]
bs_pos = uniform2d(bs_num - 1, const.L)
bs_pos = macro_bs_init(bs_pos, const.L)
ue_pos = uniform2d(ue_num, const.L)

# 初始化光伏能量
p_pv = np.random.poisson(const.PV_A, [1, const.BS_NUM])  # shape=[24, bs_num]
s_pv = [const.S_PV_MICRO for i in range(const.BS_NUM - 1)]
s_pv.insert(0, const.S_PV_MACRO)
p_pv = p_pv * s_pv * const.GAMMA_PV
# 初始化用户要求和信道状态
ue_snr_theta = np.random.randint(const.SINR_MIN, const.SINR_MAX, size=[ue_num, 1])
h_bs_ue = channel_status(bs_num, ue_num)

bs_status = np.array([[1, 0, 0, 0]])
ce_temp = 1000
l_bs_ue = distance_calculation(bs_pos, ue_pos)  # 测算距离
_, rb_req = rb_demand(ue_snr_theta, l_bs_ue, h_bs_ue)
result_userassociation_energysharing = userassociation_energysharing_once(bs_num, ue_num, bs_pos, ue_pos, p_pv, rb_req,
                                                                          l_bs_ue, h_bs_ue)
print(result_userassociation_energysharing.ce)

